/*=================================================================================
 * The functions of TimeAdv
 *=================================================================================*/

/*---------------------------------------------------------------------------------
 * Standard C++ library headers
 *---------------------------------------------------------------------------------*/

#include <iostream>

/*---------------------------------------------------------------------------------
 * Local headers
 *---------------------------------------------------------------------------------*/

#include "TimeAdv.h"

/*---------------------------------------------------------------------------------
	Name:		TimeAdv::EE

	Input(8):	The Number of species; The time step;
				The mesh nodes and boundary nodes;
				The Flux; The current residual value

	Function:	Use the 1st-order Euler Explicit Scheme

	Return:		The residual value after dt
*---------------------------------------------------------------------------------*/

void TimeAdv::EE(int NS, double dt, Array<double> xnode, Array<double> ynode, int bc, Array<double> F, Array<double> G, Array<double> &RHS)
{

	int ni = xnode.GetSize() - 2 * bc;
	int nj = ynode.GetSize() - 2 * bc;

	for (int j = bc; j < nj + bc; j++)
		for (int i = bc; i < ni + bc; i++)
			for (int k = 0; k < NS + 3; k++)
				RHS(i, j, k) = -dt / (xnode(i) - xnode(i - 1)) * (F(i, j, k) - F(i - 1, j, k)) - dt / (ynode(j) - ynode(j - 1)) * (G(i, j, k) - G(i, j - 1, k));
}

/*---------------------------------------------------------------------------------
	Name:		TimeAdv::TVD_RK3

	Input(8):	The Number of species; The time step;
				The mesh nodes and boundary nodes;
				The Flux; The current residual value

	Function:	Use the 3rd-order TVD Runge-Kutta Scheme

	Return:		The flow field value after dt
 *---------------------------------------------------------------------------------*/

void TimeAdv::TVD_RK3(int NS, double dt, Array<double> xnode, Array<double> ynode, int bc, Array<double> F, Array<double> G, Array<double> &RHS)
{
	int ni = xnode.GetSize();
	int nj = ynode.GetSize();

	for (int j = bc; j < nj + bc; j++)
		for (int i = bc; i < ni + bc; i++)
			for (int k = 0; k < NS + 3; k++)
				RHS(i, j, k) = RHS(i, j, k);
}